import { createRouter, createWebHashHistory } from 'vue-router'

import Home from '@/components/Home.vue'
import Welcome from '@/views/Welcome.vue'
import System from '@/views/System.vue'
import Audit from '@/views/Audit.vue'
import About from "@/components/About.vue"
// // import Login from '../views/Login.vue'
const routes = [
    {
        name:'home',
        path: '/',
        component: Home,
        meta: {
            breakLink: true,
            title: '首页'
        },
        redirect: '/welcome',
        children:[
            {
                name: 'welcome',
                path: '/welcome',
                meta: {
                    title: '欢迎页'
                },
                component: Welcome
            },
            {
                name: 'about',
                path: '/about',
                meta: {
                    title: '关于我们'
                },
                component: About
            },
            {
                name: 'system',
                path: '/system',
                meta: {
                    title: '系统管理'
                },
                component: System,
                children: [
                    {
                        name: 'User',
                        path: 'user',
                        meta: {
                            title: '用户管理'
                        },
                        component: () => import('@/views/User.vue')
                    },
                    {
                        name: 'Menu',
                        path: 'menu',
                        meta: {
                            title: '菜单管理'
                        },
                        component: () => import('@/views/Menu.vue')
                    },
                    {
                        name: 'Role',
                        path: 'role',
                        meta: {
                            title: '角色管理'
                        },
                        component: () => import('@/views/Role.vue')
                    },
                    {
                        name: 'Dept',
                        path: 'dept',
                        meta: {
                            title: '部门管理'
                        },
                        component: () => import('@/views/Dept.vue')
                    }
                ]
            },
            {
                name: 'Audit',
                path: '/audit',
                meta: {
                    title: '审批管理'
                },
                component: Audit,
                children: [
                    {
                        name: 'Leave',
                        path: 'leave',
                        meta: {
                            title: '休假申请'
                        },
                        component: () => import('@/views/Leave.vue')
                    },
                    {
                        name: 'Approve',
                        path: 'approve',
                        meta: {
                            title: '待我审批'
                        },
                        component: () => import('@/views/Approve.vue')
                    },
                ]
            }
        ]
    },
    {
        name: 'login',
        path: '/login',
        component: () => import('@/views/Login.vue')
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 路由守卫/导航守卫
router.beforeEach((to, from, next) => {
    //beforeEach是router的钩子函数，在进入路由前执行
    if (to.meta.title) {
        //判断是否有标题
        // console.log(to.meta.title)
        document.title = `管理平台-${to.meta.title}`
    } else {
        document.title = '管理平台'
    }
    next()

})

export default router
